<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>转换过滤器</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="filters.string.html">« 字符串过滤器</a></li>
      <li style="float: right;"><a href="filters.compression.html">压缩过滤器 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="filters.html">可用过滤器列表</a></li>
    <li>转换过滤器</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="filters.convert" class="section">
    <h2 class="title">转换过滤器</h2>
    <p class="simpara">如同 string.* 过滤器，convert.* 过滤器的作用就和其名字一样。对于指定过滤器的更多信息，请参考该函数的手册页。</p>

 <div class="section" id="filters.convert.base64">
  <h2 class="title">convert.base64-encode 和 convert.base64-decode</h2>
    <p class="simpara">
     使用这两个过滤器等同于分别用
    <span class="function"><a href="function.base64-encode.html" class="function">base64_encode()</a></span> 和 
    <span class="function"><a href="function.base64-decode.html" class="function">base64_decode()</a></span>
    函数处理所有的流数据。<code class="literal">convert.base64-encode</code> 支持以一个关联数组给出的参数。如果给出了 
    <code class="parameter">line-length</code>，base64 输出将被用 
    <code class="parameter">line-length</code> 个字符为 长度而截成块。如果给出了 
    <code class="parameter">line-break-chars</code>，每块将被用给出的字符隔开。这些参数的效果和用 
    <span class="function"><a href="function.base64-encode.html" class="function">base64_encode()</a></span> 再加上 
    <span class="function"><a href="function.chunk-split.html" class="function">chunk_split()</a></span> 相同。</p>
    <div class="example" id="example-5522">
      <p><strong>示例 #1 convert.base64-encode &amp; convert.base64-decode</strong></p>
      <div class="example-contents">
        <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'convert.base64-encode'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;输出：&nbsp;VGhpcyBpcyBhIHRlc3QuCg==&nbsp;&nbsp;*/<br /><br /></span><span style="color: #0000BB">$param&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'line-length'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">8</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'line-break-chars'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">"\r\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'convert.base64-encode'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">STREAM_FILTER_WRITE</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$param</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;输出：&nbsp;VGhpcyBp<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;：&nbsp;cyBhIHRl<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;：&nbsp;c3QuCg==&nbsp;&nbsp;*/<br /><br /></span><span style="color: #0000BB">$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'convert.base64-decode'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"VGhpcyBpcyBhIHRlc3QuCg=="</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;输出：&nbsp;This&nbsp;is&nbsp;a&nbsp;test.&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>

  <div class="section" id="filters.covert.quoted-printable">
   <h2 class="title">convert.quoted-printable-encode 和 convert.quoted-printable-decode</h2>
   <p class="simpara">
    使用此过滤器的 decode 版本等同于用 <span class="function"><a href="function.quoted-printable-decode.html" class="function">quoted_printable_decode()</a></span>
    函数处理所有的流数据。没有和 <code class="literal">convert.quoted-printable-encode</code> 
    相对应的函数。<code class="literal">convert.quoted-printable-encode</code> 
    支持以一个关联数组给出的参数。除了支持和 <code class="literal">convert.base64-encode</code> 
    一样的附加参数外，<code class="literal">convert.quoted-printable-encode</code> 还支持布尔参数 
    <code class="parameter">binary</code> 和
    <code class="parameter">force-encode-first</code>。<code class="literal">convert.base64-decode</code>
    只支持 <code class="parameter">line-break-chars</code> 参数作为从编码载荷中剥离的类型提示。
   </p>
   <div class="example" id="example-5523">
    <p><strong>示例 #2 
     convert.quoted-printable-encode &amp; convert.quoted-printable-decode
    </strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'convert.quoted-printable-encode'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"This&nbsp;is&nbsp;a&nbsp;test.\n"</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;输出：&nbsp;=This&nbsp;is&nbsp;a&nbsp;test.=0A&nbsp;&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </div>

  <div class="section" id="filters.convert.iconv">
   <h2 class="title">convert.iconv.*</h2>
    <p class="simpara">
     在激活 <a href="book.iconv.html" class="link">iconv</a>
     的前提下可以使用 <code class="literal">convert.iconv.*</code> 压缩过滤器，
     等同于用 <span class="function"><a href="function.iconv.html" class="function">iconv()</a></span> 处理所有的流数据。

     该过滤器不支持参数，但可使用输入/输出的编码名称，组成过滤器名称，比如
     <code class="literal">convert.iconv.&lt;input-encoding&gt;.&lt;output-encoding&gt;</code> 或
     <code class="literal">convert.iconv.&lt;input-encoding&gt;/&lt;output-encoding&gt;</code>
     （两种写法的语义都相同）。
    </p>

    <div class="example" id="example-5524">
     <p><strong>示例 #3 convert.iconv.*</strong></p>
     <div class="example-contents">
      <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$fp&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'php://output'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">stream_filter_append</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'convert.iconv.utf-16le.utf-8'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fwrite</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"T\0h\0i\0s\0&nbsp;\0i\0s\0&nbsp;\0a\0&nbsp;\0t\0e\0s\0t\0.\0\n\0"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">fclose</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br /></span><span style="color: #FF8000">/*&nbsp;输出：This&nbsp;is&nbsp;a&nbsp;test.&nbsp;*/<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
     </div>

    </div>
   </div>
  </div></div></div></body></html>